/* ----------------------------------------------------------------------
*
* Copyright (C) 2025 XiaoFei. All rights reserved.
*
* $file:		XiaoZhi_W25Q64.h
* $Date:        14-January-2025
* $Revision: 	V1
* $Project: 	XiaoFei BSP Library
* $Taobao:      https://item.taobao.com/item.htm?abbucket=17&id=794365371281
*
* -------------------------------------------------------------------- */

#ifndef __XiaoZhi_W25Q64_H
#define __XiaoZhi_W25Q64_H

#define W25Q54_RCC_CS					RCC_APB2Periph_GPIOA
#define W25Q54_GPIO_CS					GPIOA
#define W25Q54_PIN_CS					GPIO_Pin_0
#define W25Q54_RCC_MISO					RCC_APB2Periph_GPIOA
#define W25Q54_GPIO_MISO                GPIOA
#define W25Q54_PIN_MISO                 GPIO_Pin_1
#define W25Q54_RCC_MOSI					RCC_APB2Periph_GPIOA
#define W25Q54_GPIO_MOSI                GPIOA
#define W25Q54_PIN_MOSI                 GPIO_Pin_2
#define W25Q54_RCC_CLK					RCC_APB2Periph_GPIOA
#define W25Q54_GPIO_CLK                 GPIOA
#define W25Q54_PIN_CLK                  GPIO_Pin_3

#define W25Q64_WRI_EN					0x06
#define W25Q64_WRI_DIS					0x04
#define W25Q64_RE_REGISTER_1		    0x05
#define W25Q64_RE_REGISTER_2		    0x35
#define W25Q64_WR_REGISTER			    0x01
#define W25Q64_PAGE_PROG				0x02
#define W25Q64_QUAD_PAGE_PROG		    0x32
#define W25Q64_BLOCK_64KB				0xD8
#define W25Q64_BLOCK_32KB				0x52
#define W25Q64_SECTOR_4KB				0x20
#define W25Q64_CHIP						0xC7
#define W25Q64_ERASE_SUSPEND		    0x75
#define W25Q64_ERASE_RESUME			    0x7A
#define W25Q64_POWER_DOWN				0xB9
#define W25Q64_HIGH_PERMODE			    0xA3
#define W25Q64_CON_READ_RESET		    0xFF
#define W25Q64_RE_POWERDOWN_ID	        0xAB
#define W25Q64_MANUFACTURER_ID	        0x90
#define W25Q64_READ_UNIQUE_ID		    0x4B
#define W25Q64_JEDEC_ID					0x9F
#define W25Q64_READ_DATA				0x03
#define W25Q64_FAST						0x0B
#define W25Q64_FAST_DU_OUT			    0x3B
#define W25Q64_FAST_DU_IO				0xBB
#define W25Q64_FAST_QU_OUT			    0x6B
#define W25Q64_FAST_QU_IO				0xEB
#define W25Q64_OC_READ_QU_IO		    0xE3
#define W25Q64_DUMMY_BYTE				0xFF

#define W25Q64_CS(x)					GPIO_WriteBit(W25Q54_GPIO_CS,W25Q54_PIN_CS,(BitAction)x)
#define W25Q64_CLK(x)					GPIO_WriteBit(W25Q54_GPIO_CLK,W25Q54_PIN_CLK,(BitAction)x)
#define W25Q64_MOSI(x)					GPIO_WriteBit(W25Q54_GPIO_MOSI,W25Q54_PIN_MOSI,(BitAction)x)
#define W25Q64_MISO						GPIO_ReadInputDataBit(W25Q54_GPIO_MISO, W25Q54_PIN_MISO)

/* 
* @function: 	W25Q64_Init
*/
void W25Q64_Init(void);

/* 
* @function: 	W25Q64_ReadID
* @parameter:	[out] MID					 The ID number from manufactory.
* @parameter:	[out] DID					 The ID number from device.
*/
void W25Q64_ReadID(unsigned char *MID, unsigned short int *DID);

/* 
* @function: 	W25Q64_PageProgram
* @parameter:	[in] Address                 The start address of page program.
* @parameter:	[in] DataArray				 The first address of the written array.
* @parameter:	[in] Count					 The size of the written array.
*/
void W25Q64_PageProgram(unsigned int Address, unsigned char *DataArray, unsigned short int Count);

/* 
* @function: 	W25Q64_SectorErase
* @parameter:	[in] Address                 The start address of sector erase.
*/
void W25Q64_SectorErase(unsigned int Address);

/* 
* @function: 	W25Q64_ReadData
* @parameter:	[in] Address                 The start address of reading data.
* @parameter:	[out] DataArray				 The first address of the data to be read.
* @parameter:	[in] Count					 The size of the data to be read.
*/
void W25Q64_ReadData(unsigned int Address, unsigned char* DataArray, unsigned int Count);

#endif

